package price;


import cmsparse.TextUtils;

import java.net.URLDecoder;

/**
 * Created by wangxingsheng on 2020/6/24.
 */
public class URLDecoderTest {
    static String iosUrl = "%7B%22action%22:%22NATIVE_GOODS_VIDEO_DIALOG%22,%22param%22:%7B%22itemCode%22:%2215076445%22,%22isBone%22:%220%22,%22videoUrl%22:%22http://domhttp.kksmg.com/2016/05/17/h264_450k_mp4_8d304dee2fc4c8a9d3222ca32feaa2e3_ncd.mp4%22,%22itemName%22:%22%E5%A5%88%E5%A3%AB%E8%BF%AA%2095%25%E8%B4%A1%E7%BC%8E%E7%99%BD%E9%B9%85%E7%BB%92%E7%BE%BD%E7%BB%92%E8%A2%AB1400g%20%20A214-SD%EF%BC%88200*230cm%EF%BC%89%22,%22salePrice%22:%222198%22,%22integral%22:%220%22,%22imgUrl%22:%22%22%7D%7D";
    static String androidUrl = "https://www.ocj.com.cn/#{%22action%22:%22NATIVE_GOODS_VIDEO_DIALOG%22,%22param%22:{%22itemCode%22:%2215076445%22,%22isBone%22:%220%22,%22videoUrl%22:%22http://domhttp.kksmg.com/2016/05/17/h264_450k_mp4_8d304dee2fc4c8a9d3222ca32feaa2e3_ncd.mp4%22,%22itemName%22:%22%E5%A5%88%E5%A3%AB%E8%BF%AA%2095%%E8%B4%A1%E7%BC%8E%E7%99%BD%E9%B9%85%E7%BB%92%E7%BE%BD%E7%BB%92%E8%A2%AB1400g%20%20A214-SD%EF%BC%88200*230cm%EF%BC%89%22,%22salePrice%22:%222198%22,%22integral%22:%220%22,%22imgUrl%22:%22%22}}";

    public static void main(String[] args) {
        try {
            System.out.println(iosUrl);
            iosUrl = urlPreDecoder(iosUrl);
            System.out.println(iosUrl);
            System.out.println(URLDecoder.decode(iosUrl, "UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            System.out.println(androidUrl);
            androidUrl = urlPreDecoder(androidUrl);
            System.out.println(androidUrl);
            System.out.println(URLDecoder.decode(androidUrl, "UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String urlPreDecoder(String url) {
        if (TextUtils.isEmpty(url)) {
            return url;
        }
        return url.replaceAll("%(?![0-9a-fA-F]{2})", "%25").replaceAll("\\+", "%2B");
    }
}
